// import cookieparser from 'cookieparser'
// import Cookies from 'js-cookie'
// import Hashes from 'jshashes'
import {getUserMenuTree} from '~/api/'

const actions = {
    async nuxtServerInit({ state, commit }, { app, isDev, req, redirect }) {
        app.$axios.setHeader('Cookie', req.Cookie)
        try {
          const res = await getUserMenuTree(app)
          if (res.code == '0') {
            console.log(res.message)
            commit('TOGGLE_STATE', 'isLogin')
            commit('SET_MENU', res.data.menu)
          }
        } catch (error) {
          console.log(error)
        }
        // let accessToken = ''
        // if (req.headers.cookie) {
        //     let cookie = cookieparser.parse(req.headers.cookie)
        //     accessToken = cookie.accessToken
        // }
        // if (accessToken !== '') {
        //     commit('TOGGLE_STATE', 'isLogin')
        // }
    },
    setLoginStatus({ commit }, account = false) {
        commit('TOGGLE_STATE', 'isLogin')
        // if (!account) {
        //     Cookies.remove('ACCESS_TOKEN')
        // } else {
        //     let accessToken = new Hashes.MD5().hex(account)
        //     Cookies.set('ACCESS_TOKEN', accessToken, { expires: 1 })
        // }
    }
}
export default actions
